<#include "/common/_layout.html">
<#assign pageJavascript>
<script type="text/javascript">
var upuser = function(id,btype){
	$("#level").attr("data-id",id);
	$("#level").val(btype);
	$('#myModal').modal('show');
};
var delit = function(obj){
	var tr = $(obj).parent().parent("tr").attr("id");
	var id = tr.replace("tr_","");
	listPage.deleteTr(tr,id);
};
var updatebtype = function(){
	var loadIndex = layer.load();
	$.ajax({
		type: "POST",url: "/admin/device/device/updatebtype",
		cache:false,data: {
          	id:$("#level").attr("data-id"),btype:$("#level").val()
		},
		success: function(data) {
			if (data.msg == 'success') {
				layer.alert('设置成功！',{icon: 6},function(index){
					layer.close(index);
				});
				listPage.gopage(10,1);
           	}
   	       	else {
				layer.msg(data.msg, {icon: 5});
			}
			$('#myModal').modal('hide');
		}
	});
};
$(function(){
	listPage.config = {listUrl:"/admin/device/device/bindprofile",delUrl:"/admin/device/device/binddelete"};
	listPage.showlist = function(data){
		if(data.list == undefined) return false;
		$("#showlist").empty();
		$.each(data.list, function (i, row) {
			var str = '<tr id="tr_'+row.id+'"><td><input value="'+row.id+'" type="checkbox"></td><td>'+row.username+'</td><td>'+(row.btype=='8'?'机主':(row.btype=='2'?'预警人员':'普通用户'))+'</td><td>'+null2blank(row.udname)
				+'</td><td>'+row.bindtime+'</td><td><button class="btn btn-xs btn-default" onclick="upuser(\''+row.id+'\',\''+row.btype+'\')">设置类型</button>'
				+'&nbsp;<button class="btn btn-xs btn-danger" onclick="delit(this)">删除</button></td></tr>';
			$("#showlist").append(str);
		});
		$("#page").page({total:data.totalRow,currentpage:data.pageNumber,gopage:listPage.gopage,pagesize:data.pageSize});
	};
	$("#querybtn").click(function(){
		listPage.gopage(10,1);
	});
	$("#selectbtn").click(function(){
		if($(this).is(":checked")){
			$(this).parents("table").first().find(":checkbox").prop("checked",true);;
		}
		else{
			$(this).parents("table").first().find(":checkbox").prop("checked",false);;
		}
	});
	$("#delsbtn").click(function(){
		var ids = "";
		$("#showlist").find("input:checked").each(function(){
			ids += "'"+$(this).val()+"',";
		});
		if(ids.length>0){
			listPage.deleteTrs(ids.substr(0,ids.length-1));
		}
	});
	$("#querybtn").click();
});
</script>
</#assign>
<#assign pageCss>
<link rel="stylesheet" type="text/css" href="/assets/uploadfive/uploadifive.css" />
<style type="text/css">
</style>
</#assign>
<@layout pageTitle="设备管理" pageJavascript=pageJavascript pageCss=pageCss>		
<#include "/admin/device/_menu.html">
<!-- Modal -->
<h3 class="page-header">绑定列表</h3>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">设置类型</h4>
      </div>
      <div class="modal-body">
      	<form class="form-horizontal" id="modalForm">
			<div class="form-group">
				<label for="deviceProduct.ptype" class="col-sm-2 control-label">设备类型</label>
				<div class="col-sm-5">
					<select class="form-control" id="level">			    		
						<option value="0">普通用户</option>
						<option value="2">预警人员</option>
						<option value="8">机主</option>
					</select>
				</div>
			</div>
	   </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-success" onclick="updatebtype()" >确认</button>
      </div>
    </div>
  </div>
</div>
<div class="panel panel-default">
  <div class="panel-body filter">
	<div class="form-inline">
		<div class="form-group">
			<input type="hidden" id="t.deviceid" value="${device.id!}" data-rule="eq">
			<label for="nickname">用户帐号</label> 
			<input type="text" class="form-control" id="username" data-rule="like">
	    	<label>绑定时间：</label>
		    <input class="form-control" style="width:160px" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="input" data-rule="ge" id="start_t.bindtime" >～
			<input class="form-control" style="width:160px" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="input" data-rule="le" id="end_t.bindtime" >
		</div>   
		<button id="querybtn" class="btn btn-default">查询</button>
		<button id="delsbtn" class="btn btn-danger">批量删除</button>
		<a href="/admin/device/device" class="btn btn-warning">返回</a>
	</div>
  </div>
</div>
<table class="table table-bordered table-hover table-striped">
	<thead>
		<tr>
			<th width="30px"><input id="selectbtn" type="checkbox"></th>			
			<th>用户账号</th>
			<th>用户类型</th>
			<th>设备备注名</th>
			<th>绑定时间</th>			
			<th>操作</th>
		</tr>
	</thead>
	<tbody id="showlist"></tbody>
</table>
<nav><ul id="page" class="pagination"></ul></nav>
</@layout>